<?php

/*
	info: 全局上传
*/

define('NOT_HTMLPAGE', TRUE);
define('NOT_LOGIN', TRUE);
require dirname(__FILE__).'/include/common.inc.php';
require WEBFILEPATH.'/include/upload.class.php';
require WEBFILEPATH.'/include/image.class.php';

@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
header("Content-Type: application/json; charset=".$webconfig['webcharset']);

$tempsavepath = WEBFILEPATH.'/files/';

$tempupload = new Upload('Filedata', array('type'=>array('jpg','jpeg','gif','png'), 'notype'=>array(), 'size'=>2097152));
if ($tempupload->CheckFile())
{
	$tempfolder = global_FormatTime(0, 'Ym');
	$tempsavepath .= $tempfolder;
	if (!is_dir($tempsavepath))
	{
		@mkdir($tempsavepath, 0777, true);
		@touch($tempsavepath.'/index.htm');
	}
	$tempupload->SaveFile($tempsavepath);
	$tempfile = $tempupload->fileList[0];
	$tempimagerate = ($tempupload->fileList[0]['height'] >  $tempupload->fileList[0]['width']) ? 1 : 0;
	echo '{"status":1,"oldname":"'.$tempupload->fileList[0]['oldname'].'","filename":"'.$tempupload->fileList[0]['name'].'","abspathfile":"'.urlencode($tempfolder.'/'.$tempupload->fileList[0]['name']).'","pathfile":"'.$tempfolder.'/'.$tempupload->fileList[0]['name'].'","imagerate":'.$tempimagerate.'}';
}
else
{
	echo '{"status":0,"errorinfo":"'.$tempupload->errorMsg.'"}';
}
